package com.dtw.ditouwang.ui.mine;

import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dtw.ditouwang.R;
import com.dtw.ditouwang.beans.MyMedalBean;

import java.util.List;

public class MedalGroupAdapter extends RecyclerView.Adapter<MedalGroupAdapter.Holder> {
    private List<MyMedalBean.DataBeanX> medalGroupList;

    public MedalGroupAdapter(List<MyMedalBean.DataBeanX> medalGroupList) {

        this.medalGroupList = medalGroupList;
    }

    @NonNull
    @Override
    public Holder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new Holder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_medal_group, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int i) {
        holder.textView.setText(medalGroupList.get(i).getType_name());
        MedalAdapter medalAdapter = new MedalAdapter(medalGroupList.get(i).getData());
        holder.recyclerView.setLayoutManager(new GridLayoutManager(holder.itemView.getContext(),4));
        holder.recyclerView.setAdapter(medalAdapter);
    }

    @Override
    public int getItemCount() {
        return medalGroupList.size();
    }

    class Holder extends RecyclerView.ViewHolder {
        TextView textView;
        RecyclerView recyclerView;

        public Holder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.text_group_name);
            recyclerView = itemView.findViewById(R.id.recyclerview);
        }
    }
}
